package com.ysw.spring.api_security.idempotent.controller;

import com.ysw.dto.ResponseResult;
import com.ysw.spring.api_security.idempotent.config.CheckIdempotent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author: yu_sw
 * @Description: com.ysw.spring.api_security.idempotent.controller
 * @date:2023/3/20 14:15
 */
@RestController
@RequestMapping("/repeat")
public class TestController {
    @Autowired
    StringRedisTemplate redisTemplate;
    @RequestMapping("/getToken")
    public String getToken(){
        String uid = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(uid, uid);
        redisTemplate.expire(uid, 30, TimeUnit.SECONDS);
        return uid;
    }
    @RequestMapping("/testRepeat")
    @CheckIdempotent
    public ResponseResult testRepeat(){
        return ResponseResult.success();
    }
}
